import request from 'axios';
// request.defaults.baseURL="http://192.168.0.106:8081"
// request.defaults.baseURL="http://127.0.0.1:8081"

import config from '../../project.config'
request.defaults.baseURL=config.serverAddress

let axios=request.create({
	  headers: {
	        'x-token-shitian':localStorage.getItem('token') as string
	  }
})

let $axios=request.create({
	  headers: {
	         'Content-Type': 'application/x-www-form-urlencoded',
	        'x-token-shitian':localStorage.getItem('token') as string
	  }
})
$axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

function network(parms:object):object{
	return new Promise((resolve,reject)=>{
		axios(parms).then(
			result=>{
				resolve(result.data)
			},
			err=>{
				reject(err)
			}
		)
	});
};

network.get=(url:string):object=>{
	return axios.get(url);
}
network.post=(url:string,parms:object,token?:string):object=>{
	return $axios.post(url,parms,{
		headers: token?{
		      'x-token-shitian':token
		}:{}
	});
}

export default network;
	
